#include<iostream>
#include<pthread.h>
#include<cstdio>
#include<string>
#include<unistd.h>


void show(const std::string name)
{
    std::cout<<name<<",pid:"<<getpid()<<std::endl;
}

void* threadFun(void* args)
{
    const std::string name=(char*)args;
    while(true)
    {
        show(name);
        sleep(1);
    }
}

int main()
{
    pthread_t tid[5];
    char name[64];
    for(int i=0;i<5;i++)
    {
        snprintf(name,sizeof(name),"%s-%i","thread",i);
        pthread_create(tid+i,nullptr,threadFun,(void*)name);
        sleep(1);//缓解传参的Bug
    }

    while(true)
    {
        std::cout<<"main thread,pid:"<<getpid()<<std::endl;
        sleep(5);
    }
    return 0;
}